<template>
  <div>
    <div style="height: 100vh; overflow-y: auto;">
      <el-form label-width="100px" class="form" label-position="left" v-if="!isTime">
        <el-form-item label="模块名称" v-if="!hasPrograss || (form.warehousingStatus === '' || form.warehousingStatus === '0')">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="form.warehousingBelongName" readonly :disabled="!canEdit">
            <el-button slot="append" @click="changePrograss" :disabled="!canEdit">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="模块名称" v-if="hasPrograss && (form.warehousingStatus !== '' && form.warehousingStatus !== '0')">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="form.warehousingBelongName" disabled></el-input>
        </el-form-item>
        <el-form-item label="分箱号">
          <el-input v-model="form.warehousingBoxNumber" :disabled="!canEdit"></el-input>
        </el-form-item>
        <el-form-item label="单据编号">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <div @click="changePlan">
            <el-input v-model="form.warehousingPlanId" readonly :disabled="!canEdit || hasPlanNumber" suffix-icon="el-icon-arrow-down"></el-input>
          </div>
        </el-form-item>
        <el-form-item label="产品编号">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <div @click="showProductDialog">
            <el-input v-model="form.warehousingProductId" readonly :disabled="!canEdit" suffix-icon="el-icon-arrow-down"></el-input>
          </div>
        </el-form-item>
        <el-form-item label="产品名称">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <div @click="showProductDialog">
            <el-input type="textarea" :autosize="{minRows: 1}" v-model="form.warehousingProductName" readonly :disabled="!canEdit"></el-input>
          </div>
        </el-form-item>
        <el-form-item label="产品简称" v-if="hasArugList.indexOf('productAbbreviation') !== -1">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="form.warehousingProductAbbreviation" :disabled="!canEdit"></el-input>
        </el-form-item>
        <el-form-item label="生产基地" v-if="hasArugList.indexOf('productBase') !== -1">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="form.warehousingProductBase" :disabled="!canEdit"></el-input>
        </el-form-item>
        <el-form-item label="工序名称" v-if="hasArugList.indexOf('productProcess') !== -1">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="form.warehousingProductProcess" :disabled="!canEdit"></el-input>
        </el-form-item>
        <el-form-item label="产成品类别" v-if="hasArugList.indexOf('productType') !== -1">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="form.warehousingProductType" readonly :disabled="!canEdit">
            <el-button slot="append" @click="changeProductType" :disabled="!canEdit">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="产品类别" v-if="hasArugList.indexOf('productCategory') !== -1">
          <el-input v-model="form.warehousingProductCategory" multiple readonly :disabled="!canEdit">
            <el-button slot="append" @click="changeProductCategory" :disabled="!canEdit">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="使用模具">
          <div @click="changeProductMold">
            <el-input v-model="form.warehousingProductMoldName" readonly :disabled="!canEdit" suffix-icon="el-icon-arrow-down"></el-input>
          </div>
        </el-form-item>
        <el-form-item label="使用设备">
          <div @click="changeProductEquipment">
            <el-input v-model="form.warehousingProductEquipmentName" readonly :disabled="!canEdit" suffix-icon="el-icon-arrow-down"></el-input>
          </div>
        </el-form-item>
        <el-form-item label="生产车间">
          <el-input v-model="form.warehousingProductWorkshop" :disabled="!canEdit"></el-input>
        </el-form-item>
        <el-form-item label="工艺" v-show="hasArugList.indexOf('craft') !== -1">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="form.warehousingCraftName" readonly :disabled="!canEdit">
            <el-button slot="append" @click="changeCraft" :disabled="!canEdit">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="表面颜色" v-if="hasArugList.indexOf('color') !== -1">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="form.warehousingProductColor" readonly :disabled="!canEdit">
            <el-button slot="append" @click="changeProductColor" :disabled="!canEdit">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="商标" v-if="hasArugList.indexOf('productTrademark') !== -1">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="form.warehousingProductTrademark" readonly :disabled="!canEdit">
            <el-button slot="append" @click="changeProductTrademark" :disabled="!canEdit">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="产品结构" v-if="hasArugList.indexOf('productStructure') !== -1">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="form.warehousingProductStructure" readonly :disabled="!canEdit">
            <el-button slot="append" @click="changeProductStructure" :disabled="!canEdit">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="生产方式" v-if="hasArugList.indexOf('productMode') !== -1">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="form.warehousingProductMode" readonly :disabled="!canEdit">
            <el-button slot="append" @click="changeProductMode" :disabled="!canEdit">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="入库数量">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="form.warehousingNumber" type="number" min="0" :disabled="!canEdit" @wheel.native.prevent="stopScrollFun($event)"></el-input>
        </el-form-item>
        <el-form-item label="班组" v-if="hasArugList.indexOf('team') !== -1">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="form.warehousingTeamName" readonly :disabled="!canEdit">
            <el-button slot="append" @click="changeTeam" :disabled="!canEdit">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="参与人员" v-if="hasArugList.indexOf('team') !== -1">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <div class="select-btn" @click="selectDingUsers(300)"><span><i class="el-icon-plus"></i></span>添加</div>
          <div v-for="(item, index) in form.warehousingParticipantNamesArr" :key="index">
            <div class="select-btn" style="padding: 0;" @click="delMember(index)">{{item}}<div class="del" v-if="canEdit">移除</div></div>
          </div>
        </el-form-item>
        <div>
          <p>1、计件本人填写此单据；</p>
          <p>2、品质部填写同意，示为产品合格、产品编码，产品名称填写准确，且每箱产品均有完整的标识状态；</p>
          <p>3、计件薪资依签收数量为准；</p>
          <p>4、此单据同时作为生产入库单、生产日报表、薪资计算单，FQC检验记录单。</p>
        </div>
        <el-steps direction="vertical" :active="(Number(form.warehousingStatus)-1)">
          <el-step v-for="(user, userIdx) in operator" :key="userIdx">
            <div slot="description">
              <div class="steps-wrapper">
                <div class="top">
                  <span class="name">{{user.name}}</span>
                  <div v-if="user.type==='2'" class="right">
                    <div class="select-btn" v-if="form.warehousingQualityAuditId.length !== 1" @click="showSelectUserDialog('2')"><span><i class="el-icon-plus"></i></span>添加</div>
                    <div v-for="(mem, memIdx) in form.warehousingQualityAuditName" :key="memIdx" v-else>
                      <div class="select-btn" style="padding: 0;" @click="showSelectUserDialog('2')">{{mem}}</div>
                    </div>
                  </div>
                  <div v-if="user.type==='3'" class="right">
                    <div class="select-btn" v-if="form.warehousingSignForId.length !== 1" @click="showSelectUserDialog('3')"><span><i class="el-icon-plus"></i></span>添加</div>
                    <div v-for="(mem, memIdx) in form.warehousingSignForName" :key="memIdx" v-else>
                      <div class="select-btn" style="padding: 0;" @click="showSelectUserDialog('3')">{{mem}}</div>
                    </div>
                  </div>
                  <div v-if="user.type==='4'" class="right">
                    <div class="select-btn" v-if="form.warehousingInputId.length !== 1" @click="showSelectUserDialog('4')"><span><i class="el-icon-plus"></i></span>添加</div>
                    <div v-for="(mem, memIdx) in form.warehousingInputName" :key="memIdx" v-else>
                      <div class="select-btn" style="padding: 0;" @click="showSelectUserDialog('4')">{{mem}}</div>
                    </div>
                  </div>
                  <div v-if="user.type==='5'" class="right">
                    <div v-for="(mem, memIdx) in form.warehousingCcName" :key="memIdx">
                      <div class="select-btn" style="padding: 0;">{{mem}}</div>
                    </div>
                  </div>
                </div>
                <div class="content">
                  <p v-if="user.type==='2'">入库产品合格数量：{{form.warehousingQualifiedNumber}}</p>
                  <p v-if="user.type==='3'">实际入库数量：{{form.warehousingRealNumber}}</p>
                  <p v-if="user.type==='3' && form.warehousingInstruction">入库说明：{{form.warehousingInstruction}}</p>
                </div>
              </div>
            </div>
          </el-step>
        </el-steps>
        <div style="display: flex; justify-content: space-between; margin-top: 20px;">
          <div></div>
          <div>
            <el-button @click="$router.go(-1)" size="mini">取消</el-button>
            <el-button type="primary" @click="submitForm(false)" size="mini" v-if="canEdit">提交</el-button>
            <el-button type="danger" @click="submitForm(true, false)" size="mini" v-if="canCheck && (form.warehousingStatus === '2' || form.warehousingStatus === '1')">驳回</el-button>
            <el-button type="primary" @click="showCheckDialog" size="mini" v-if="canCheck">审核<span v-if="form.warehousingStatus === '3'">通过</span></el-button>
          </div>
        </div>
      </el-form>
      <el-form label-width="100px" class="form" label-position="left" v-if="isTime">
        <el-form-item label="班组">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="timeForm.subsidyTeamName" readonly :disabled="!canEdit">
            <el-button slot="append" @click="changeTeam" :disabled="!canEdit">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="参与人员">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <div class="select-btn" @click="selectDingUsers(300)"><span><i class="el-icon-plus"></i></span>添加</div>
          <div v-for="(item, index) in timeForm.subsidyParticipantNamesArr" :key="index">
            <div class="select-btn" style="padding: 0;" @click="delMember(index)">{{item}}<div class="del" v-if="canEdit">移除</div></div>
          </div>
        </el-form-item>
        <el-form-item label="计时人数">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="timeForm.subsidyStaffNumber" type="number" min="0" :disabled="!canEdit" @wheel.native.prevent="stopScrollFun($event)"></el-input>
        </el-form-item>
        <el-form-item label="工作内容">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="timeForm.subsidyContent" type="textarea" min="0" :disabled="!canEdit"></el-input>
        </el-form-item>
        <el-form-item label="补贴时间说明">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="timeForm.subsidyTimeDescription" type="textarea" min="0" :disabled="!canEdit"></el-input>
        </el-form-item>
        <el-form-item label="其他支持文件">
          <input ref="uploadInput" style="display:none;" type="file" @change="uploadFile($event, timeForm.subsidyAttachment)" multiple="multiple">
          <el-button type="text" @click="$refs.uploadInput.click()" v-if="canEdit">选择</el-button>
          <el-button type="text" disabled v-else>选择</el-button>
          <div class="fileitem" v-for="(file, idx) in timeForm.subsidyAttachment" :key="idx">
            <span style="cursor: pointer;" @click="downloadFile(file.url, file.name)">
              <img style="width:16px;height:16px;position:relative;top:-2px;margin-right:2px;" :src="getPic(file.name)" alt="">{{file.name}}
            </span>
            <span class="uploadtip" v-if="file.url && canEdit" @click="delFile(idx, timeForm.subsidyAttachment)"><i class="el-icon-delete"></i></span>
            <span class="uploadtip" style="color: red;cursor:none;" v-if="!file.url">上传中<i class="el-icon-loading"></i></span>
          </div>
        </el-form-item>
        <el-form-item label="补贴对象">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="timeForm.subsidyPensonType" readonly :disabled="!canEdit">
            <el-button slot="append" @click="changePensonType" :disabled="!canEdit">选择</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="申请补贴时间">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="timeForm.subsidyTotalTime" type="number" min="0" :disabled="!canEdit" @wheel.native.prevent="stopScrollFun($event)"></el-input>
        </el-form-item>
        <el-form-item label="实际补贴时间" v-if="timeForm.id">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input v-model="timeForm.subsidyTotalRealTime" disabled></el-input>
        </el-form-item>
        <el-form-item label="补贴标准">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input type="number" v-model="timeForm.subsidyStandard" :disabled="!canEdit" @wheel.native.prevent="stopScrollFun($event)">
            <el-button slot="append">元/小时</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="补贴费用">
          <span style="color: red; position:absolute; left: -110px;">*</span>
          <el-input :value="!timeForm.id ? timeForm.subsidyStandard * timeForm.subsidyTotalTime : timeForm.subsidyStandard * timeForm.subsidyTotalRealTime" :disabled="true"></el-input>
        </el-form-item>
        <div>
          <p>1、若属于跨部门支援计时，由确认人转交给相关部门主管核实；</p>
          <p>2、计时依班组为单位进行申请，禁止填写一个班组，勾选多个班组的人员。</p>
        </div>
        <el-steps direction="vertical" :active="(Number(timeForm.subsidyStatus)-1)">
          <el-step v-for="(user, userIdx) in operator" :key="userIdx">
            <div slot="description">
              <div class="steps-wrapper">
                <div class="top">
                  <span class="name">{{user.timeName}}</span>
                  <div v-if="user.type==='2'" class="right">
                    <div class="select-btn" v-if="timeForm.subsidyDepartmentPrincipalId.length !== 1" @click="showSelectUserDialog('2')"><span><i class="el-icon-plus"></i></span>添加</div>
                    <div v-for="(mem, memIdx) in timeForm.subsidyDepartmentPrincipalName" :key="memIdx" v-else>
                      <div class="select-btn" style="padding: 0;" @click="showSelectUserDialog('2')">{{mem}}</div>
                    </div>
                  </div>
                  <div v-if="user.type==='3'" class="right">
                    <div class="select-btn" v-if="timeForm.subsidyCenterPrincipalId.length !== 1" @click="showSelectUserDialog('3')"><span><i class="el-icon-plus"></i></span>添加</div>
                    <div v-for="(mem, memIdx) in timeForm.subsidyCenterPrincipalName" :key="memIdx" v-else>
                      <div class="select-btn" style="padding: 0;" @click="showSelectUserDialog('3')">{{mem}}</div>
                    </div>
                  </div>
                  <div v-if="user.type==='4'" class="right">
                    <div class="select-btn" v-if="timeForm.subsidySalarySpecialistId.length !== 1" @click="showSelectUserDialog('4')"><span><i class="el-icon-plus"></i></span>添加</div>
                    <div v-for="(mem, memIdx) in timeForm.subsidySalarySpecialistName" :key="memIdx" v-else>
                      <div class="select-btn" style="padding: 0;" @click="showSelectUserDialog('4')">{{mem}}</div>
                    </div>
                  </div>
                  <div v-if="user.type==='5'" class="right">
                    <div v-for="(mem, memIdx) in timeForm.subsidyCcName" :key="memIdx">
                      <div class="select-btn" style="padding: 0;">{{mem}}</div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </el-step>
        </el-steps>
        <div style="display: flex; justify-content: space-between; margin-top: 20px;">
          <div></div>
          <div>
            <el-button @click="$router.go(-1)" size="mini">取消</el-button>
            <el-button type="primary" @click="submitTimeForm(false)" size="mini" v-if="canEdit">提交</el-button>
          <el-button type="danger" @click="submitTimeForm(true, false)" size="mini" v-if="canCheck && this.timeForm.subsidyStatus !== '1'">驳回</el-button>
          <el-button type="primary" @click="checkTimeForm" size="mini" v-if="canCheck">审核</el-button>
          </div>
        </div>
      </el-form>
    </div>
    <div class="product-wrapper" v-if="userDialogVisible">
      <div class="mask" ref="userMask" @click.stop="closeUserSelect" @touchmove.prevent></div>
      <div :class="animationName" class="addContent" style="height: 50vh;">
        <div class="goal-header">
          <i class="el-icon-arrow-down" @click.stop="closeUserSelect"></i>
          <span>请选择操作人员</span>
        </div>
        <div style="padding: 20px;">
          <div v-for="authority in authorityList" :key="authority.id">
            <div v-if="authority.pcAuthorityDatatype === curType" style="display: flex;">
              <div style="width: 100px; height: 28px; line-height: 28px;margin-bottom: 10px;">{{isTime ? operator[Number(authority.pcAuthorityDatatype) - 2].timeName : operator[Number(authority.pcAuthorityDatatype) - 2].name}}</div>
              <div style="flex: 1; display: flex; flex-wrap: wrap;">
                <div v-for="(mem, memIdx) in authority.namesArr" :key="memIdx">
                  <div class="select-btn" style="padding: 0;" @click="selectUser(authority.idsArr[memIdx], mem)">{{mem}}</div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="product-wrapper" v-if="checkDialogVisible">
      <div class="mask" ref="checkMask" @click.stop="closeCheckSelect" @touchmove.prevent></div>
      <div :class="animationName" class="addContent" style="height: 50vh;">
        <div class="goal-header">
          <i class="el-icon-arrow-down" @click.stop="closeCheckSelect"></i>
          <span>审核</span>
        </div>
        <div style="padding: 20px;" v-if="!isTime">
          <el-form label-width="130px" label-position="left">
            <el-form-item label="入库产品合格数量" v-if="form.warehousingStatus === '1'">
              <span style="color: red; position:absolute; left: -140px;">*</span>
              <el-input v-model="form.warehousingQualifiedNumber" type="number" min="0"></el-input>
            </el-form-item>
            <el-form-item label="实际入库数量" v-if="form.warehousingStatus === '2'">
              <span style="color: red; position:absolute; left: -140px;">*</span>
              <el-input v-model="form.warehousingRealNumber" type="number" min="0"></el-input>
            </el-form-item>
            <el-form-item label="入库说明" v-if="form.warehousingStatus === '2'">
              <el-input v-model="form.warehousingInstruction" type="textarea"></el-input>
            </el-form-item>
          </el-form>
          <span slot="footer" style="display: flex; justify-content: space-between;">
            <div></div>
            <div>
              <el-button @click="checkDialogVisible = false" size="mini">取消</el-button>
              <el-button type="primary" @click="submitForm(true, true)" size="mini">审核通过</el-button>
            </div>
          </span>
        </div>
        <div style="padding: 20px;" v-if="isTime">
          <el-form label-width="130px" label-position="left">
            <el-form-item label="实际补贴时间">
              <el-input v-model="timeForm.subsidyTotalRealTime" type="number"></el-input>
            </el-form-item>
          </el-form>
          <span slot="footer" style="display: flex; justify-content: space-between;">
            <div></div>
            <div>
              <el-button @click="checkDialogVisible = false" size="mini">取消</el-button>
              <el-button type="primary" @click="submitTimeForm(true, true)" size="mini">审核通过</el-button>
            </div>
          </span>
        </div>
      </div>
    </div>
    <div class="product-wrapper" v-if="productDialogVisible">
      <div class="mask" ref="mask" @click.stop="closeSelect" @touchmove.prevent></div>
      <div :class="animationName" class="addContent">
        <div class="goal-header">
          <i class="el-icon-arrow-down" @click.stop="closeSelect"></i>
          <span>产品列表</span>
        </div>
        <div style="height: 50px; line-height: 50px; display: flex; padding: 0 20px;">
          <el-input v-model="searchPost.productId" placeholder="请输入产品编号" clearable style="margin-right: 20px;"></el-input>
          <el-input v-model="searchPost.productName" placeholder="请输入产品名称" clearable style="margin-right: 20px;"></el-input>
          <span><el-button type="primary" size="mini" @click="getProductList(true)">查询</el-button></span>
        </div>
        <div class="dept-list" v-infinite-scroll="loadData" infinite-scroll-disabled="disabled" infinite-scroll-immediate="false">
          <div class="dept-item" v-for="product in dataList.productList" :key="product.id" @click="chooseProduct(product)">
            <div class="dept-name">{{product.productId}}</div>
            <div class="dept-next">{{product.productName}}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import dingMixin from  '@/mixins/ding'
import * as dd from 'dingtalk-jsapi'
import formUtil from '@/utils/formUtil'
import {dateUtil} from '@/utils/dateUtil'
export default {
  name: '',
  data () {
    return {
      form: {
        warehousingBelongId: "",
        warehousingBelongName: "",
        warehousingPlanId: "",
        warehousingProductId: "",
        warehousingProductName: "",
        warehousingProductAbbreviation: "",
        warehousingCraftId: "",
        warehousingCraftName: "",
        warehousingProductProcess: "",
        warehousingProductMode: "",
        warehousingProductColor: "",
        warehousingProductTrademark: "",
        warehousingProductStructure: "",
        warehousingProductType: "",
        warehousingProductMoldId: "",
        warehousingProductMoldName: "",
        warehousingProductEquipmentId: "",
        warehousingProductEquipmentName: "",
        warehousingProductBase: "",
        warehousingNumber: "",
        warehousingQualifiedNumber: "",
        warehousingRealNumber: "",
        warehousingInstruction: "",
        warehousingQualityAuditId: "",
        warehousingQualityAuditName: "",
        warehousingSignForId: "",
        warehousingSignForName: "",
        warehousingInputId: "",
        warehousingInputName: "",
        warehousingCcId: "",
        warehousingCcName: "",
        warehousingTeamId: "",
        warehousingTeamName: "",
        warehousingParticipantId: "",
        warehousingParticipantName: "",
        warehousingStatus: "",
        warehousingParticipantIdsArr: [],
        warehousingParticipantNamesArr: [],
        warehousingBoxNumber: "",
        // warehousingProductCategory: '',
        warehousingProductCategory: [],
        warehousingProductWorkshop: '',
      },
      // warehousingProductCategoryName: '',
      timeForm: {
        subsidyTeamId: "",
        subsidyTeamName: "",
        subsidyParticipantId: "",
        subsidyParticipantName: "",
        subsidyParticipantIdsArr: [],
        subsidyParticipantNamesArr: [],
        subsidyStaffNumber: "",
        subsidyContent: "",
        subsidyTimeDescription: "",
        subsidyAttachment: "",
        subsidyPensonType: "",
        subsidyTotalTime: "",
        subsidyStandard: "",
        subsidyFee: "",
        subsidyDepartmentPrincipalId: "",
        subsidyDepartmentPrincipalName: "",
        subsidyCenterPrincipalId: "",
        subsidyCenterPrincipalName: "",
        subsidySalarySpecialistId: "",
        subsidySalarySpecialistName: "",
        subsidyCcId: "",
        subsidyCcName: "",
        subsidyStatus: "",
        subsidyTotalRealTime: ""
      },
      dataList: {
        process: [],
        planList: [],
        productList: [],
        craftList: [],
        assetsList: {
          assets1: [],
          assets2: [],
        },
        productCategoryList: [],  //产品类别
      },
      authorityListInit: [],
      authorityList: [],
      warehousingBelongId: '',
      warehousingBelongName: '',
      userDialogVisible: false,
      checkDialogVisible: false,
      curType: '',
      operator: [{type: '2', name: '品质审核', timeName: '部门主管'},{type: '3', name: '签收人员', timeName: '制造中心'},{type: '4', name: 'ERP录入', timeName: '薪酬专员'},{type: '5', name: '抄送人员', timeName: '抄送人员'}],
      groupList: [],
      operation: '',
      hasPrograss: true,  //是否有所属工艺：压玻璃面板、机械装配……
      hasPlanNumber: true,  //是否从生产计划那边计件过来
      productDialogVisible: false,
      page: 1,
      totalPage: 1,
      pageSize: 20,
      isFirstLoading: true,
      loading: false,
      searchPost: {
        productId: '',
        productName: ''
      },
      animationName: 'open'
    };
  },
  computed: {
    disabled () {
      return this.isFirstLoading || this.loading || this.noMore
    },
    noMore () {
      return this.page >= this.totalPage;
    },
    isTime() {
      return this.warehousingBelongId === '1293102120648929281'       //生产部计时（是否为计时模块）
    },
    hasArugList() {
      if(this.warehousingBelongId === '1293101541625262081') {        //压玻璃面板
        return ['craft', 'color', 'productTrademark', 'productStructure']
      } else if(this.warehousingBelongId === '1293101625096105986') { //力沃包装
        return ['productCategory', 'productStructure']
      } else if(this.warehousingBelongId === '1293101643356778834') { //力范包装
        return ['productCategory', 'productStructure']
      } else if(this.warehousingBelongId === '1293101695052902401') { //焊接组
        return ['productAbbreviation']
      } else if(this.warehousingBelongId === '1293101746550566913') { //程序烧录
        return ['productAbbreviation']
      } else if(this.warehousingBelongId === '1293101824271020034') { //电子开关装配
        return ['productProcess', 'productAbbreviation']
      } else if(this.warehousingBelongId === '1293101860946014209') { //注塑车间
        return ['productMode']
      } else if(this.warehousingBelongId === '1293101911722258434') { //丝印工序
        return ['productMode']
      } else if(this.warehousingBelongId === '1293102001933348866') { //计时岗位
        return ['productBase', 'productProcess', 'productType', 'team']
      } else {
        return []
      }
    },
    canEdit() {
      return this.operation === 'edit' || (!this.form.id && !this.isTime) || (!this.timeForm.id && this.isTime)
    },
    canCheck() {
      return this.operation === 'check' &&
      (!this.isTime && 
        ((this.form.warehousingStatus==='1' && this.form.warehousingQualityAuditId.includes(this.userInfo.dingId)) || 
        (this.form.warehousingStatus==='2' && this.form.warehousingSignForId.includes(this.userInfo.dingId)) || 
        (this.form.warehousingStatus==='3' && this.form.warehousingInputId.includes(this.userInfo.dingId)))) ||
      (this.isTime && 
        ((this.timeForm.subsidyStatus==='1' && this.timeForm.subsidyDepartmentPrincipalId.includes(this.userInfo.dingId)) || 
        (this.timeForm.subsidyStatus==='2' && this.timeForm.subsidyCenterPrincipalId.includes(this.userInfo.dingId)) || 
        (this.timeForm.subsidyStatus==='3' && this.timeForm.subsidySalarySpecialistId.includes(this.userInfo.dingId))))
    }
  },
  mixins: [dingMixin],
  components: {},
  watch: {
    searchPost: {
      handler() {
        this.getProductList(true)
      },
      deep: true
    }
  },
  mounted () {
    this.init(this.$route.params.id, this.$route.params.warehousingBelongId, this.$route.params.warehousingBelongName, this.$route.params.operation, this.$route.params.planNumber)
  },
  methods: {
    async init(id, warehousingBelongId, warehousingBelongName, operation, planNumber='') {
      this.operation = operation;
      !planNumber ? this.hasPlanNumber = false : true
      if(!warehousingBelongId) {
        this.hasPrograss = false
        this.warehousingBelongId = ''
      } else {
        this.hasPrograss = true
        this.warehousingBelongId = warehousingBelongId
      }
      this.warehousingBelongName = warehousingBelongName;
      this.getGroupList()
      if(!this.isTime) {
        formUtil.resetData(this.form);
        await this.getPeiceWorkList()
        this.getPlanList()
        this.getCraftList()
        this.getAssetsList()
        if(id) {
          this.form = await this.$httpN.postB('pc/warehousing/info', {id: id})
          if(this.form) {
            if(this.form.warehousingStatus !== '0' && this.form.warehousingBelongName) this.warehousingBelongName = this.form.warehousingBelongName
            this.$set(this.form, "warehousingParticipantIdsArr", this.form.warehousingParticipantId === '' ? [] : this.form.warehousingParticipantId.split(','))
            this.$set(this.form, "warehousingParticipantNamesArr", this.form.warehousingParticipantName === '' ? [] : this.form.warehousingParticipantName.split(','))
            this.form.warehousingQualityAuditId = this.form.warehousingQualityAuditId === '' ? [] : this.form.warehousingQualityAuditId.split(',');
            this.form.warehousingQualityAuditName = this.form.warehousingQualityAuditName === '' ? [] :  this.form.warehousingQualityAuditName.split(',');
            this.form.warehousingSignForId = this.form.warehousingSignForId === '' ? [] :  this.form.warehousingSignForId.split(',');
            this.form.warehousingSignForName = this.form.warehousingSignForName === '' ? [] :  this.form.warehousingSignForName.split(',');
            this.form.warehousingInputId = this.form.warehousingInputId === '' ? [] :  this.form.warehousingInputId.split(',');
            this.form.warehousingInputName = this.form.warehousingInputName === '' ? [] :  this.form.warehousingInputName.split(',');
            this.form.warehousingCcId = this.form.warehousingCcId === '' ? [] :  this.form.warehousingCcId.split(',');
            this.form.warehousingCcName = this.form.warehousingCcName === '' ? [] :  this.form.warehousingCcName.split(',');
            this.form.warehousingProductCategory = this.form.warehousingProductCategory === '' ? [] : this.form.warehousingProductCategory.split(',');
            
            if(this.form.warehousingStatus === '0' && !this.form.warehousingBelongId && this.warehousingBelongId) {
              this.form.warehousingBelongId = this.warehousingBelongId
              this.form.warehousingBelongName = this.warehousingBelongName
              this.getAuthorityList()
            }
            if((this.form.warehousingStatus === '0' || this.form.warehousingStatus === '') && this.operation === 'check') this.operation = 'edit'
          }
        } else {
          this.form.warehousingStatus = '1'
          this.form.warehousingBelongId = this.warehousingBelongId
          this.form.warehousingBelongName = this.warehousingBelongName
          if(planNumber) this.form.warehousingPlanId = planNumber
        }
      } else {
        formUtil.resetData(this.timeForm);
        if(id) {
          this.timeForm = await this.$httpN.postB('pc/subsidy/info', {id: id})
          if(!this.warehousingBelongName) this.warehousingBelongName = '生产部计时';
          this.$set(this.timeForm, "subsidyParticipantIdsArr", this.timeForm.subsidyParticipantId === '' ? [] : this.timeForm.subsidyParticipantId.split(','))
          this.$set(this.timeForm, "subsidyParticipantNamesArr", this.timeForm.subsidyParticipantName === '' ? [] : this.timeForm.subsidyParticipantName.split(','))
          this.timeForm.subsidyAttachment ? this.timeForm.subsidyAttachment = JSON.parse(this.timeForm.subsidyAttachment) : this.timeForm.subsidyAttachment = [];
          this.timeForm.subsidyDepartmentPrincipalId = this.timeForm.subsidyDepartmentPrincipalId === '' ? [] : this.timeForm.subsidyDepartmentPrincipalId.split(',');
          this.timeForm.subsidyDepartmentPrincipalName = this.timeForm.subsidyDepartmentPrincipalName === '' ? [] :  this.timeForm.subsidyDepartmentPrincipalName.split(',');
          this.timeForm.subsidyCenterPrincipalId = this.timeForm.subsidyCenterPrincipalId === '' ? [] : this.timeForm.subsidyCenterPrincipalId.split(',');
          this.timeForm.subsidyCenterPrincipalName = this.timeForm.subsidyCenterPrincipalName === '' ? [] :  this.timeForm.subsidyCenterPrincipalName.split(',');
          this.timeForm.subsidySalarySpecialistId = this.timeForm.subsidySalarySpecialistId === '' ? [] : this.timeForm.subsidySalarySpecialistId.split(',');
          this.timeForm.subsidySalarySpecialistName = this.timeForm.subsidySalarySpecialistName === '' ? [] :  this.timeForm.subsidySalarySpecialistName.split(',');
          this.timeForm.subsidyCcId = this.timeForm.subsidyCcId === '' ? [] : this.timeForm.subsidyCcId.split(',');
          this.timeForm.subsidyCcName = this.timeForm.subsidyCcName === '' ? [] :  this.timeForm.subsidyCcName.split(',');
        } else {
          this.timeForm.subsidyStatus = '1'
          this.timeForm.warehousingBelongId = this.warehousingBelongId
          this.timeForm.warehousingBelongName = this.warehousingBelongName
          this.timeForm.subsidyAttachment = []
        }
      }
    },
    //计件模块列表
    async getPeiceWorkList () {
      let data = await this.$httpN.postB('pc/dict/list', {pid: '1293101384636657666', limit: 999})
      this.dataList.process = data.list.filter(item => { return item.id !== '1293102120648929281' })
      this.dataList.process.forEach((item) => {
        item.key = item.name;
        item.value = item.id;
      })
      let data2 = await this.$httpN.postB('pc/dict/list', {pid: '1315851988961968130', limit: 999})
      this.dataList.productCategoryList = data2.list;
      this.dataList.productCategoryList.forEach((item) => {
        item.key = item.name;
        item.value = item.id;
      })
    },
    async getPlanList() {
      let data = await this.$httpN.postB('pc/authority/asd');
      let {list} = await this.$httpN.postB('pc/plan/list', {limit: 999, searchType: data.userLevel === '1' || data.userLevel === '2' ? '0' : '1', planStatus: '1'})
      this.dataList.planList = list.filter(item => {
        return item.planBelongId === this.form.warehousingBelongId || item.planBelongId === ''
      })
      this.dataList.planList.forEach((item) => {
        item.key = item.planNumber;
        item.value = item.id;
      })
    },
    showProductDialog() {
      if(!this.canEdit) return
      formUtil.resetData(this.searchPost);
      this.getProductList(true)
      this.productDialogVisible = true;
      this.$nextTick(() => {
        this.$refs.mask.style.opacity = 0.5;
      })
    },
    loadData() {
      this.loading = true;
      this.page ++;
      this.getProductList();
    },
    async getProductList(init) {
      if(init) {
        this.page = 1;
        this.dataList.productList = [];
        this.isFirstLoading = true;
      }
      let {list, totalPage} = await this.$httpN.postB('pc/product/list',{
        page: this.page,
        limit: this.pageSize,
        productId: this.searchPost.productId,
        productName: this.searchPost.productName
      });
      this.loading = false;
      this.dataList.productList.push(...list)
      if(init) {
        this.totalPage = totalPage;
        this.$nextTick(() => {
          this.isFirstLoading = false;
        })
      }
    },
    chooseProduct(product) {
      this.form.warehousingProductId = product.productId
      this.form.warehousingProductName = product.productName
      this.productDialogVisible = false;
    },
    async getAssetsList() {
      let data1 = await this.$httpN.postB('pc/assets/list', {assetsType: '1', limit: 999})
      let data2 = await this.$httpN.postB('pc/assets/list', {assetsType: '2', limit: 999})
      this.dataList.assetsList.assets1 = data1.list;
      this.dataList.assetsList.assets1.forEach((item) => {
        item.key = item.assetsName;
        item.value = item.assetsNumber;
      })
      this.dataList.assetsList.assets2 = data2.list;
      this.dataList.assetsList.assets2.forEach((item) => {
        item.key = item.assetsName;
        item.value = item.assetsNumber;
      })
    },
    async getCraftList() {
      let {list} = await this.$httpN.postB('pc/craft/list', {limit: 999})
      this.dataList.craftList = list
      this.dataList.craftList.forEach((item) => {
        item.key = item.craftName;
        item.value = item.id;
      })
    },
    showCheckDialog() {
      if(this.form.warehousingStatus === '1' || this.form.warehousingStatus === '2') {
        this.checkDialogVisible = true;
        this.$nextTick(() => {
          this.$refs.checkMask.style.opacity = 0.5;
        })
      } else {
        this.submitForm(true, true);
      }
    },
    changePrograss() {
      this.mobileChosen(this.dataList.process, this.form.warehousingBelongName, (data) => {
        this.form.warehousingBelongId = data.value;
        this.form.warehousingBelongName = data.key;
        this.warehousingBelongId = this.form.warehousingBelongId;
        this.getAuthorityList();
      })
    },
    changePlan() {
      if(!this.canEdit || this.hasPlanNumber) return
      this.mobileChosen(this.dataList.planList, this.form.warehousingPlanId, (data) => {
        this.form.warehousingPlanId = data.key;
      })
    },
    changeCraft() {
      let arr = this.dataList.craftList.filter(item => item.craftBelongId === this.form.warehousingBelongId)
      this.mobileChosen(arr, this.form.warehousingCraftName, (data) => {
        this.form.warehousingCraftId = data.value;
        this.form.warehousingCraftName = data.key;
      })
    },
    changeProductCategory() {
      var that = this
      dd.biz.util.multiSelect({
        options: this.dataList.productCategoryList.map(item => item.key),
        selectOption: this.form.warehousingProductCategory,
        onSuccess: function(result) {
          that.form.warehousingProductCategory = []
          result.forEach(selectIdx => {
            that.form.warehousingProductCategory.push(that.dataList.productCategoryList[selectIdx].key)
          })
        },
        onFail: function() {}
      })
    },
    changeProductMold() {
      if(!this.canEdit) return
      this.mobileChosen(this.dataList.assetsList.assets1, this.form.warehousingProductMoldName, (data) => {
        this.form.warehousingProductMoldId = data.value;
        this.form.warehousingProductMoldName = data.key;
      })
    },
    changeProductEquipment() {
      if(!this.canEdit) return
      this.mobileChosen(this.dataList.assetsList.assets2, this.form.warehousingProductEquipmentName, (data) => {
        this.form.warehousingProductEquipmentId = data.value;
        this.form.warehousingProductEquipmentName = data.key;
      })
    },
    changeTeam() {
      this.mobileChosen(this.groupList, !this.isTime ? this.form.warehousingTeamName : this.timeForm.subsidyTeamName, (data) => {
        if(!this.isTime) {
          this.form.warehousingTeamId = data.value;
          this.form.warehousingTeamName = data.key;
        } else {
          this.timeForm.subsidyTeamId = data.value;
          this.timeForm.subsidyTeamName = data.key;
        }
        this.selectGroup()
      })
    },
    changeProductType() {
      this.mobileChosen([{value: '成品', key: '成品'}, {value: '半成品', key: '半成品'}], this.form.warehousingProductType, (data) => {
        this.form.warehousingProductType = data.value;
      })
    },
    changeProductColor() {
      this.mobileChosen([{value: '白', key: '白'}, {value: '黑', key: '黑'}, {value: '金', key: '金'}, {value: '灰', key: '灰'}, 
        {value: '粉', key: '粉'}, {value: '绿', key: '绿'}, {value: '蓝', key: '蓝'}], this.form.warehousingProductColor, (data) => {
        this.form.warehousingProductColor = data.value;
      })
    },
    changeProductTrademark() {
      this.mobileChosen([{value: '公司商标', key: '公司商标'}, {value: '客户商标', key: '客户商标'}, {value: '无', key: '无'}], this.form.warehousingProductTrademark, (data) => {
        this.form.warehousingProductTrademark = data.value;
      })
    },
    changeProductStructure() {
      this.mobileChosen([{value: '单联', key: '单联'}, {value: '双联', key: '双联'}, {value: '三联', key: '三联'}, {value: '四联', key: '四联'}, {value: '五联', key: '五联'}, {value: '无', key: '无'} ], this.form.warehousingProductStructure, (data) => {
        this.form.warehousingProductStructure = data.value;
      })
    },
    changeProductMode() {
      this.mobileChosen([{value: '全自动', key: '全自动'}, {value: '半自动', key: '半自动'}], this.form.warehousingProductMode, (data) => {
        this.form.warehousingProductMode = data.value;
      })
    },
    changePensonType() {
      this.mobileChosen([{value: '个人', key: '个人'}, {value: '班组', key: '班组'}], this.timeForm.subsidyPensonType, (data) => {
        this.timeForm.subsidyPensonType = data.value;
      })
    },
    async submitForm(check, ifPass) {
      var curStatus = this.form.warehousingStatus === '' ? '0' : this.form.warehousingStatus;
      if(this.operation === 'edit') curStatus = '1'
      if(check) {
        if(this.form.warehousingStatus === '1' && !this.form.warehousingQualifiedNumber && ifPass) return this.$message.error('请输入入库产品合格数量');
        if(this.form.warehousingStatus === '2' && !this.form.warehousingRealNumber && ifPass) return this.$message.error('请输入实际入库数量');
        if(Number(this.form.warehousingNumber) < Number(this.form.warehousingQualifiedNumber)) return this.$message.error('合格产品数量应小于等于入库产品数量');
        if(this.form.warehousingStatus === '2' && !!this.form.warehousingRealNumber && ifPass && (Number(this.form.warehousingQualifiedNumber) < Number(this.form.warehousingRealNumber))) return this.$message.error('实际入库数量应小于等于合格产品数量');
        curStatus = ifPass ? (Number(this.form.warehousingStatus) + 1).toString() : (Number(this.form.warehousingStatus) - 1).toString();
      }
      if(!this.form.warehousingBelongId ) return this.$message.error('请输入或选择模块名称');
      if(!this.form.warehousingPlanId ) return this.$message.error('请输入或选择单据编号');
      if(!this.form.warehousingProductId) return this.$message.error('请输入或选择产品编号');
      if(!this.form.warehousingProductName) return this.$message.error('请输入或选择产品名称');
      if(!this.form.warehousingProductAbbreviation && (this.hasArugList.indexOf('productAbbreviation') !== -1) ) return this.$message.error('请输入产品简称');
      if(!this.form.warehousingProductBase && (this.hasArugList.indexOf('productBase') !== -1) ) return this.$message.error('请输入生产基地');
      if(!this.form.warehousingProductProcess && (this.hasArugList.indexOf('productProcess') !== -1) ) return this.$message.error('请输入工序名称');
      if(!this.form.warehousingProductType && (this.hasArugList.indexOf('productType') !== -1) ) return this.$message.error('请选择产成品类别');
      // if(!this.form.warehousingCraftId && (this.hasArugList.indexOf('craft') !== -1) ) return this.$message.error('请选择工艺');
      // if(!this.form.warehousingProductColor && (this.hasArugList.indexOf('color') !== -1)) return this.$message.error('请选择表面颜色');
      if(!this.form.warehousingProductTrademark && (this.hasArugList.indexOf('productTrademark') !== -1)) return this.$message.error('请选择商标');
      if(!this.form.warehousingProductStructure && (this.hasArugList.indexOf('productStructure') !== -1) && !this.canCheck) return this.$message.error('请选择产品结构');
      if(!this.form.warehousingProductMode && (this.hasArugList.indexOf('productMode') !== -1)) return this.$message.error('请选择产品生产方式');
      if(!this.form.warehousingTeamId && (this.hasArugList.indexOf('team') !== -1)) return this.$message.error('请选择班组');
      if(!this.form.warehousingParticipantId && (this.hasArugList.indexOf('team') !== -1)) return this.$message.error('请选择参与人员');
      if(!this.form.warehousingNumber) return this.$message.error('请输入入库数量');
      if(this.form.warehousingQualityAuditId.length !== 1) return this.$message.error('请选择品质审核人');
      if(this.form.warehousingSignForId.length !== 1) return this.$message.error('请选择入库签收人');
      if(this.form.warehousingInputId.length !== 1) return this.$message.error('请选择erp录入人员');
      var data = {
        warehousingBelongId: this.form.warehousingBelongId,
        warehousingBelongName: this.form.warehousingBelongName,
        warehousingPlanId: this.form.warehousingPlanId,
        warehousingProductId: this.form.warehousingProductId,
        warehousingProductName: this.form.warehousingProductName,
        warehousingProductAbbreviation: this.form.warehousingProductAbbreviation,
        warehousingCraftId: this.form.warehousingCraftId,
        warehousingCraftName: this.form.warehousingCraftName,
        warehousingProductProcess: this.form.warehousingProductProcess,
        warehousingProductMode: this.form.warehousingProductMode,
        warehousingProductColor: this.form.warehousingProductColor,
        warehousingProductTrademark: this.form.warehousingProductTrademark,
        warehousingProductStructure: this.form.warehousingProductStructure,
        warehousingProductType: this.form.warehousingProductType,
        warehousingProductCategory: this.form.warehousingProductCategory.join(","),
        warehousingProductWorkshop: this.form.warehousingProductWorkshop,
        warehousingProductMoldId: this.form.warehousingProductMoldId,
        warehousingProductMoldName: this.form.warehousingProductMoldName,
        warehousingProductEquipmentId: this.form.warehousingProductEquipmentId,
        warehousingProductEquipmentName: this.form.warehousingProductEquipmentName,
        warehousingProductBase: this.form.warehousingProductBase,
        warehousingNumber: this.form.warehousingNumber.toString(),
        warehousingQualifiedNumber: this.form.warehousingQualifiedNumber.toString(),
        warehousingRealNumber: this.form.warehousingRealNumber.toString(),
        warehousingInstruction: this.form.warehousingInstruction,
        warehousingQualityAuditId: this.form.warehousingQualityAuditId.join(","),
        warehousingQualityAuditName: this.form.warehousingQualityAuditName.join(","),
        warehousingSignForId: this.form.warehousingSignForId.join(","),
        warehousingSignForName: this.form.warehousingSignForName.join(","),
        warehousingInputId: this.form.warehousingInputId.join(","),
        warehousingInputName: this.form.warehousingInputName.join(","),
        warehousingCcId: this.form.warehousingCcId.join(","),
        warehousingCcName: this.form.warehousingCcName.join(","),
        warehousingTeamId: this.form.warehousingTeamId,
        warehousingTeamName: this.form.warehousingTeamName,
        warehousingParticipantId: this.form.warehousingParticipantId,
        warehousingParticipantName: this.form.warehousingParticipantName,
        warehousingStatus: curStatus,
        warehousingBoxNumber: this.form.warehousingBoxNumber,
      }
      if(this.form.id) data.id = this.form.id
      if(!await this.$httpN.postB(!this.form.id ? 'pc/warehousing/save' : 'pc/warehousing/update', data)) return
      formUtil.submitSuccess('保存成功');
      window.NEEDREFRESH1 = true
      window.NEEDREFRESH2 = true
      window.NEEDREFRESH3 = true
      window.NEEDREFRESH4 = true
      this.$router.go(-1);
      this.checkDialogVisible = false;
    },
    showSelectUserDialog(type) {
      if(!this.canEdit) return
      this.userDialogVisible = true;
      this.curType = type
      this.$nextTick(() => {
        this.$refs.userMask.style.opacity = 0.5;
      })
    },
    selectUser(id, name) {
      if(this.isTime) {
        if(this.curType === '2') {
          this.timeForm.subsidyDepartmentPrincipalId = [id];
          this.timeForm.subsidyDepartmentPrincipalName = [name];
        } else if (this.curType === '3') {
          this.timeForm.subsidyCenterPrincipalId = [id];
          this.timeForm.subsidyCenterPrincipalName = [name];
        } else if (this.curType === '4') {
          this.timeForm.subsidySalarySpecialistId = [id];
          this.timeForm.subsidySalarySpecialistName = [name];
        }
      } else {
        if(this.curType === '2') {
          this.form.warehousingQualityAuditId = [id];
          this.form.warehousingQualityAuditName = [name];
        } else if (this.curType === '3') {
          this.form.warehousingSignForId = [id];
          this.form.warehousingSignForName = [name];
        } else if (this.curType === '4') {
          this.form.warehousingInputId = [id];
          this.form.warehousingInputName = [name];
        }
      }
      this.userDialogVisible = false;
    },
    getAuthorityList() {
      this.authorityList = this.authorityListInit.filter(item => { return item.pcAuthorityBelongId === this.warehousingBelongId })
      this.authorityList.forEach(item => {
        if(!this.isTime && (this.operation === 'add' || this.form.warehousingStatus === '0' || this.form.warehousingStatus === '')) {
          if(item.pcAuthorityDatatype === '2') {
            this.form.warehousingQualityAuditId = item.idsArr;
            this.form.warehousingQualityAuditName = item.namesArr;
          } else if (item.pcAuthorityDatatype === '3') {
            this.form.warehousingSignForId = item.idsArr;
            this.form.warehousingSignForName = item.namesArr;
          } else if (item.pcAuthorityDatatype === '4') {
            this.form.warehousingInputId = item.idsArr;
            this.form.warehousingInputName = item.namesArr;
          } else if (item.pcAuthorityDatatype === '5') {
            this.form.warehousingCcId = item.idsArr;
            this.form.warehousingCcName = item.namesArr;
          }
        } else if(this.isTime && this.operation === 'add') {
          if(item.pcAuthorityDatatype === '2') {
            this.timeForm.subsidyDepartmentPrincipalId = item.idsArr;
            this.timeForm.subsidyDepartmentPrincipalName = item.namesArr;
          } else if (item.pcAuthorityDatatype === '3') {
            this.timeForm.subsidyCenterPrincipalId = item.idsArr;
            this.timeForm.subsidyCenterPrincipalName = item.namesArr;
          } else if (item.pcAuthorityDatatype === '4') {
            this.timeForm.subsidySalarySpecialistId = item.idsArr;
            this.timeForm.subsidySalarySpecialistName = item.namesArr;
          } else if (item.pcAuthorityDatatype === '5') {
            this.timeForm.subsidyCcId = item.idsArr;
            this.timeForm.subsidyCcName = item.namesArr;
          }
        }
      })
    },
    async getGroupList() {
      let list = await this.$httpN.postB('pc/authority/list');
      list.forEach(item => {
        if(item.pcAuthorityUsersId !== '') {
          item.idsArr = item.pcAuthorityUsersId.split(",")
          item.namesArr = item.pcAuthorityUsersName.split(",")
        } else {
          item.idsArr = []
          item.namesArr = []
        }
      })
      list.forEach((item) => {
        item.key = item.pcAuthorityBelongName;
        item.value = item.id;
      })
      this.authorityListInit = list
      this.groupList = list.filter(item => {
        return item.pcAuthorityDatatype === '6'
      })
      if(this.warehousingBelongId) this.getAuthorityList()
    },
    selectGroup() {
      if(!this.isTime) {
        this.groupList.forEach(item => {
          if(item.id === this.form.warehousingTeamId) {
            this.form.warehousingTeamName = item.pcAuthorityBelongName;
            this.form.warehousingParticipantIdsArr = item.idsArr;
            this.form.warehousingParticipantNamesArr = item.namesArr;
            this.form.warehousingParticipantId = this.form.warehousingParticipantIdsArr.join(',');
            this.form.warehousingParticipantName = this.form.warehousingParticipantNamesArr.join(',');
          }
        })
      } else {
        this.groupList.forEach(item => {
          if(item.id === this.timeForm.subsidyTeamId) {
            this.timeForm.subsidyTeamName = item.pcAuthorityBelongName;
            this.timeForm.subsidyParticipantIdsArr = item.idsArr;
            this.timeForm.subsidyParticipantNamesArr = item.namesArr;
            this.timeForm.subsidyParticipantId = this.timeForm.subsidyParticipantIdsArr.join(',');
            this.timeForm.subsidyParticipantName = this.timeForm.subsidyParticipantNamesArr.join(',');
          }
        })
      }
    },
    delMember(idx) {
      if(!this.canEdit) return
      if(!this.isTime) {
        this.form.warehousingParticipantIdsArr.splice(idx,1); 
        this.form.warehousingParticipantNamesArr.splice(idx,1); 
        this.form.warehousingParticipantId = this.form.warehousingParticipantIdsArr.join(',');
        this.form.warehousingParticipantName = this.form.warehousingParticipantNamesArr.join(',');
      } else {
        this.timeForm.subsidyParticipantIdsArr.splice(idx,1); 
        this.timeForm.subsidyParticipantNamesArr.splice(idx,1); 
        this.timeForm.subsidyParticipantId = this.timeForm.subsidyParticipantIdsArr.join(',');
        this.timeForm.subsidyParticipantName = this.timeForm.subsidyParticipantNamesArr.join(',');
      }
    },
    selectDingUsers(num){
      if(!this.canEdit) return
      if(!this.isTime) {
        this.complexPicker(num, [], this.form.warehousingParticipantIdsArr).then((data)=>{
          this.form.warehousingParticipantIdsArr = data.map(item => item.emplId);
          this.form.warehousingParticipantNamesArr = data.map(item => item.name)
          this.form.warehousingParticipantId = this.form.warehousingParticipantIdsArr.join(',');
          this.form.warehousingParticipantName = this.form.warehousingParticipantNamesArr.join(',');
        })
      } else {
        this.complexPicker(num, [], this.timeForm.subsidyParticipantIdsArr).then((data)=>{
          this.timeForm.subsidyParticipantIdsArr = data.map(item => item.emplId);
          this.timeForm.subsidyParticipantNamesArr = data.map(item => item.name);
          this.timeForm.subsidyParticipantId = this.timeForm.subsidyParticipantIdsArr.join(',');
          this.timeForm.subsidyParticipantName = this.timeForm.subsidyParticipantNamesArr.join(',');
        })
      }
    },
    async uploadFile(e, target) {
      var files = e.target.files;
      var $this = this;
      Object.keys(files).forEach(function(key){
        var file = files[key];
        if(file.size / 1024 / 1024 > 20) return $this.$message.error('上传单个文件大小不能超过20MB!请压缩文件')
        var formData = new FormData();
        formData.append("file", file);
        formData.append("name", 'file');
        let newfile = {
          name: file.name,
          url: '',
          size: file.size,
          uploader: $this.userInfo.realName,
          time: dateUtil.thisDay()
        }
        target.push(newfile)
        $this.$httpN.upload('fileUpload', formData).then(res => {
          if(res.data.code === 0) {
            newfile.url = res.data.url;;
          }else if(res.data.code === 500) {
            $this.$message.error(res.data.msg)
            target.pop();
          }
        })
      })
      e.target.value = ''
    },
    delFile(idx,target){
      target.splice(idx, 1)
    },
    downloadFile: function (url, fileName) {//跨域文件路径、下载到本地的文件名
      if(/\.(bmp|gif|jpg|pic|png|tif|jpeg)$/.test(url)) return this.dingPreviewPic(url);
      if(!url) return;
      var x = new XMLHttpRequest();
      x.open("GET", url, true);
      x.responseType = 'blob';
      x.onload=function(e) {
        var url = window.URL.createObjectURL(x.response)
        var a = document.createElement('a');
        a.href = url
        a.download = fileName;
        a.click()
      }
      x.send();
    },
    getPic(filename) {
      if(filename) {
        if(/\.(bmp|gif|jpg|pic|png|tif|jpeg)$/.test(filename)){
          return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276438103037435905.png'
        }else if(/\.(txt)$/.test(filename)){
          return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276438530785140737.png'
        }else if(/\.(xls|xlsx)$/.test(filename)){
          return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276438725690253314.png'
        }else if(/\.(doc|docx)$/.test(filename)){
          return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276439195636850689.png'
        }else if(/\.(psd)$/.test(filename)){
          return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276439984203751426.png'
        }else if(/\.(pdf)$/.test(filename)){
          return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276440139145535490.png'
        }else if(/\.(ppt|pptx|dps|dpt)$/.test(filename)){
          return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276440657859305473.png'
        }else if(/\.(rar|zip|arj|gz)$/.test(filename)){
          return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276442063039193090.png'
        }else if(/\.(html|htm)$/.test(filename)){
          return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276442135319633921.png'
        }else if(/\.(dwg|bak|dwt)$/.test(filename)){
          return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276441741667459074.png'
        }else if(/\.(wav|aif|au|mp3|ram|wma|mmf)$/.test(filename)){
          return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276442006684524546.png'
        }else if(/\.(avi|mov|rmvb|rm|flv|mp4)$/.test(filename)){
          return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276442233483124737.png'
        }else{
          return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276436590181343234.png'
        }
      }else {
        return 'https://livolo-office.oss-cn-hangzhou.aliyuncs.com/1276436590181343234.png'
      }
    },
    async submitTimeForm(check, ifPass) {
      if(!this.timeForm.subsidyTeamId ) return this.$message.error('请输入或选择班组');
      if(this.timeForm.subsidyParticipantIdsArr.length <= 0) return this.$message.error('请选择参与人员');
      if(!this.timeForm.subsidyStaffNumber) return this.$message.error('请输入计时人数');
      if(this.timeForm.subsidyAttachment.filter(item => !item.url).length > 0) return this.$message.error('附件正在上传，请稍候……');
      if(!this.timeForm.subsidyContent) return this.$message.error('请输入工作内容');
      if(!this.timeForm.subsidyTimeDescription) return this.$message.error('请输入补贴时间说明');
      if(!this.timeForm.subsidyPensonType) return this.$message.error('请选择补贴对象');
      if(!this.timeForm.subsidyTotalTime) return this.$message.error('请输入申请补贴时间');
      if(!this.timeForm.subsidyStandard) return this.$message.error('请输入补贴标准');
      if(this.timeForm.subsidyDepartmentPrincipalId.length !== 1) return this.$message.error('请选择部门主管');
      if(this.timeForm.subsidyCenterPrincipalId.length !== 1) return this.$message.error('请选择制造中心负责人');
      if(this.timeForm.subsidySalarySpecialistId.length !== 1) return this.$message.error('请选择薪酬专员');
      if(!this.timeForm.id) this.timeForm.subsidyTotalRealTime = this.timeForm.subsidyTotalTime;
      
      this.timeForm.subsidyFee = this.timeForm.subsidyStandard * this.timeForm.subsidyTotalRealTime;
      var data = {
        subsidyAttachment: this.timeForm.subsidyAttachment,
        subsidyCcId: this.timeForm.subsidyCcId.join(","),
        subsidyCcName: this.timeForm.subsidyCcName.join(","),
        subsidyCenterPrincipalId: this.timeForm.subsidyCenterPrincipalId.join(","),
        subsidyCenterPrincipalName: this.timeForm.subsidyCenterPrincipalName.join(","),
        subsidyContent: this.timeForm.subsidyContent,
        subsidyDepartmentPrincipalId: this.timeForm.subsidyDepartmentPrincipalId.join(","),
        subsidyDepartmentPrincipalName: this.timeForm.subsidyDepartmentPrincipalName.join(","),
        subsidyFee: this.timeForm.subsidyFee,
        subsidyParticipantId: this.timeForm.subsidyParticipantId,
        subsidyParticipantName: this.timeForm.subsidyParticipantName,
        subsidyPensonType: this.timeForm.subsidyPensonType,
        subsidySalarySpecialistId: this.timeForm.subsidySalarySpecialistId.join(","),
        subsidySalarySpecialistName: this.timeForm.subsidySalarySpecialistName.join(","),
        subsidyStaffNumber: this.timeForm.subsidyStaffNumber,
        subsidyStandard: this.timeForm.subsidyStandard,
        subsidyStatus: !check ? this.timeForm.subsidyStatus : ifPass ? (Number(this.timeForm.subsidyStatus) + 1).toString() : (Number(this.timeForm.subsidyStatus) - 1).toString(),
        subsidyTeamId: this.timeForm.subsidyTeamId,
        subsidyTeamName: this.timeForm.subsidyTeamName,
        subsidyTimeDescription: this.timeForm.subsidyTimeDescription,
        subsidyTotalTime: this.timeForm.subsidyTotalTime,
        subsidyTotalRealTime: this.timeForm.subsidyTotalRealTime
      }
      if(this.timeForm.id) data.id = this.timeForm.id
      if(!await this.$httpN.postB(!this.timeForm.id ? 'pc/subsidy/save' : 'pc/subsidy/update', data)) return
      formUtil.submitSuccess('保存成功');
      window.NEEDREFRESH1 = true
      window.NEEDREFRESH2 = true
      window.NEEDREFRESH3 = true
      window.NEEDREFRESH4 = true
      this.$router.go(-1);
    },
    checkTimeForm() {
      this.checkDialogVisible = true;
      this.$nextTick(() => {
        this.$refs.checkMask.style.opacity = 0.5;
      })
    },
    stopScrollFun(evt) {
      evt = evt || window.event;
      if(evt.preventDefault) {
        // Firefox
        evt.preventDefault();
        evt.stopPropagation();
      } else {
        // IE
        evt.cancelBubble=true;
        evt.returnValue = false;
      }
      return false;
    },
    closeSelect() {
      this.animationName = 'close';
      this.$refs.mask.style.opacity = 0;
      setTimeout(() => {
        this.productDialogVisible = false;
        this.animationName = 'open';
      }, 225)
    },
    closeUserSelect() {
      this.animationName = 'close';
      this.$refs.userMask.style.opacity = 0;
      setTimeout(() => {
        this.userDialogVisible = false;
        this.animationName = 'open';
      }, 225)
    },
    closeCheckSelect() {
      this.animationName = 'close';
      this.$refs.checkMask.style.opacity = 0;
      setTimeout(() => {
        this.checkDialogVisible = false;
        this.animationName = 'open';
      }, 225)
    },
  }
}
</script>

<style lang='scss' scoped>
.form {
  padding: 20px;
  border: 1px solid #000;
  margin: 20px;
  /deep/.el-step__description {
    height: 95%;
    padding-right: 0;
  }
  /deep/ .el-input .el-input__inner, /deep/ .el-textarea .el-textarea__inner {
    color: #000;
  }
  .fileitem{
    line-height: 32px;
    margin-bottom: 5px;
    background: #F5F5F5;
    width: 100%;
    padding-left:15px;
    font-size: 12px;
    .uploadtip{
      float:right;
      margin-right: 20px;
      cursor: pointer;
    }
  }
  .steps-wrapper {
    border: 2px solid #000;
    height: 100%;
    padding: 10px 20px 0 20px;
    .top {
      min-height: 36px;
      line-height: 36px;
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      .name {
        line-height: 36px;
        display: inline-block;
        min-width: 48px;
      }
      .right {
        max-width: 510px;
        display: flex;
        flex-wrap: wrap;
        flex-direction: column-reverse;
      }
    }
    .content {
      padding-left: 50px;
      padding-bottom: 10px;
    }
  }
}
.select-btn{
  float:left;
  font-weight: normal;
  margin-right: 5px;
  margin-bottom: 10px;
  width: 80px;
  height: 28px;
  border-radius: 30px;
  background: #FAFAFA;
  border: 1px solid #ECECEC;
  position: relative;
  padding-left: 21px;
  line-height: 28px;
  color: #7982A7;
  font-size: 12px;
  text-align: center;
  cursor: pointer;
  span{
    position: absolute;
    top: 1px;
    left: 1px;
    display:block;
    height: 24px;
    width: 24px;
    background: #CACACA;
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 24px;
    img{
      width: 24px;
      height: 24px;
      border-radius: 50%;
    }
  }
  .del{
    position: absolute;
    top:0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 30px;
    color: white;
    text-align: center;
    background:rgba(130, 130, 130, 0.9);
    display: none;
  }
  &:hover{
    .del, .close{
      display: block;
    }
  }
}
.product-wrapper {
  position: fixed;
  height: 100vh;
  bottom: 0;
  left: 0;
  width: 100%;
  z-index: 1;
  .mask{
    background: rgb(0,0,0);
    height: 100%;
    position: absolute;
    top:0;
    left:0;
    transition: all 225ms;
    width: 100%;
    opacity: 0;
  }
  .addContent{
    position: absolute;
    height: 90vh;
    bottom: 0;
    left: 0;
    width: 100%;
    background: white;
    border-radius: 15px 15px 0 0 ;
    background: #F2F3F5;
    animation: btt-drawer-in 225ms cubic-bezier(0,0,.2,1) 0s;
    .goal-header{
      height: 46px;
      line-height: 46px;
      background: white;
      text-align: center;
      border-radius: 15px 15px 0 0 ;
      font-weight: bold;
      font-size: 16px;
      position: relative;
      i{
        position: absolute;
        left: 15px;
        top: 15px;
        font-weight: bold;
      }
    }
    .dept-list{
      background: white;
      padding: 0 16px;
      height: calc(100% - 120px);
      overflow: auto;
      .dept-item{
        height: 50px;
        line-height: 50px;
        position: relative;
        border-bottom: 1px solid #f6f6f6;
        .dept-name{
          font-weight: bold;
        }
        .dept-next{
          position: absolute;
          top: 0;
          right: 0;
          height: 46px;
          color: #8a8a8a;
          img{
            width: 12px;
            position: relative;
            top: -1px;
          }
        }
      }
      >div:last-child{
        border-bottom: none;
      }
    }
  }
  .addContent.open{
    animation: btt-drawer-in 225ms cubic-bezier(0,0,.2,1) 0s;
  }
  .addContent.close{
    animation: btt-drawer-out 225ms cubic-bezier(0,0,.2,1) 0s;
  }
}
</style>